package com.ikkong.qy.controller;

import java.util.HashMap;
import java.util.Map;

import com.ikkong.common.vo.User;
import com.ikkong.core.dao.Blade;
import com.ikkong.core.jfinal.ext.shiro.ShiroKit;
import com.ikkong.qy.core.WeixinBaseController;

public class WeixinLoginController extends WeixinBaseController {
	
	public void login(){
		Map<String, String> resultMap = new HashMap<>();
		String mobile = getPara("mobile");
		String pass = getPara("pass");
		 
		User user = Blade.create(User.class).findFirst("select * from tfw_user u where u.account ='"+mobile+"'", null);
		try {
			if(user != null){
				String salt = user.getSalt();
				String pwd = ShiroKit.md5(pass, salt);
				if(user.getPassword().equals(pwd)){
					resultMap.put("success", "true");
					resultMap.put("msg", "登录成功");
					resultMap.put("userId", String.valueOf(user.getTeacher_id()));
					
					renderJson(resultMap);
				}else{
					resultMap.put("success", "false");
					resultMap.put("msg", "用户名或密码不正确");				
					renderJson(resultMap);
				}
			}else{
				resultMap.put("success", "false");
				resultMap.put("msg", "用户名或密码不正确");				
				renderJson(resultMap);
			}
			return;
		} catch (Exception e) {
			e.printStackTrace();
			
		}
		resultMap = new HashMap<String, String>();
		resultMap.put("success", "false");
		resultMap.put("msg", "服务器出错");				
		renderJson(resultMap);
	}
	
	
}
